package juego

import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.widgets.Panel
import unq.model.Juego
import model.AppModel.MapamundiAppModel
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.Button
import org.uqbar.lacar.ui.model.Action
import model.PaisEditableWindows
import model.NuevoPaisWindow
import unq.model.Pais
import org.uqbar.arena.windows.SimpleWindow
import org.uqbar.arena.bindings.PropertyAdapter
import org.uqbar.arena.layout.VerticalLayout
import unq.model.Lugar

class MapamundiWindows extends SimpleWindow<MapamundiAppModel> {

	new(WindowOwner owner, MapamundiAppModel model) {
		super(owner, model)
		title = "MAPAMUNDI"
	}

	override protected createFormPanel(Panel mainPanel) {

		new Panel(mainPanel) => [setLayout(new ColumnLayout(2)) 
			crearPanelLista(it)
			crearPanelDescripcionSelecion(it)
			crearBotonera(it)]

	}

	def crearBotonera(Panel panel) {
		new Button(panel) => [
			caption = "Eliminar"
			onClick [|this.modelObject.eliminarPais]
		]
		new Button(panel) => [
			caption = "Editar"
			onClick [|(new PaisEditableWindows(this, modelObject.paisSeleccionado)).open]
		]
		new Button(panel) => [caption = "Nuevo"
			onClick [ |
				modelObject.setNuevoPais(new Pais((this.modelObject.juego)))			
				(new NuevoPaisWindow(this, this.modelObject.nuevoPais)).open
				modelObject.agregarPais
			]]

	}

	def PanelDescripcion(Panel panel, String textm, String propiedad, Class c) {
		new Label(panel) => [text = textm fontSize = 13	]
		new List(panel) => [
			bindItemsToProperty(propiedad)
			.setAdapter(new PropertyAdapter(c , "nombre"))
			width = 150
			heigth = 50
		]
	}

	def crearPanelDescripcionSelecion(Panel panel) {
		new Panel(panel) => [
			setLayout(new VerticalLayout())
			PanelDescripcionCaract(it, "caracteristicas", "paisSeleccionado.caracteristicas")
			PanelDescripcion(it, "conexiones", "paisSeleccionado.conexiones", Lugar)
			PanelDescripcion(it, "lugaresDeInteres", "paisSeleccionado.lugaresDeInteres", Pais)
		]

	}
	
	def PanelDescripcionCaract(Panel panel, String textm, String propiedad) {	new Label(panel) => [text = textm fontSize = 13]
		new List(panel) => [
			bindItemsToProperty(propiedad)
			width = 150
			heigth = 50
		]
	}

	def crearPanelLista(Panel panel) {
		new Panel(panel) => [
			setLayout(new VerticalLayout())
			new Label(it) => [text = "Paises" fontSize = 13]
			new List(it) => [
				val binding = bindItemsToProperty("juego.listaPaises")
				binding.setAdapter(new PropertyAdapter(Pais, "nombre"))
				bindValueToProperty("paisSeleccionado")
				width = 150
				heigth = 50
			]
		]

	}

	override protected addActions(Panel actionsPanel) {
		new Button(actionsPanel) => [
			caption = "cerrar Mapamundi"
			onClick [|close]
		]
	}

}
